package com.morgan.test;

import com.common.util.EncriptUtil;

public class CTEncriptSHA256 {
    
    private static final char[] sourceArray = "abcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
    private static final int lengthSourceArray =  sourceArray.length;
    private static final String target = "0815f17319e60cb47ab301546b688f021574f441a953dda39652aec62509afd6";
    
    public static void main (String[] args) {
        
        System.out.println(EncriptUtil.sha256Encode("Hehe"));

        char [] char1 = new char[1];
        generate1(char1);
        
        char [] char2 = new char[2];
        generate2(char2);
        
        char [] char3 = new char[3];
        generate3(char3);
        
        char [] char4 = new char[4];
        generate4(char4);
        
        char [] char5 = new char[5];
        generate5(char5);
        
        char [] char6 = new char[6];
        generate6(char6);
        
        char [] char7 = new char[7];
        generate7(char7);
        
        char [] char8 = new char[8];
        generate8(char8);
        
        
    }
    
    
    private static void generate1(char[] charArray) {
        for(int a = 0; a< lengthSourceArray ;a++) {
            charArray[0] = sourceArray[a];
                    
            String sStr = new String(charArray);
            if(EncriptUtil.validate(target, EncriptUtil.sha256Encode(sStr))) {
                System.out.println(sStr);
                break;
            }
        }
    }
    
    private static void generate2(char[] charArray) {
        for(int a = 0; a< lengthSourceArray ;a++) {
            charArray[0] = sourceArray[a];
            for (int b = 0; b< lengthSourceArray; b++) {
                charArray[1] = sourceArray[b];
                    
                String sStr = new String(charArray);
                if(EncriptUtil.validate(target, EncriptUtil.sha256Encode(sStr))) {
                    System.out.println(sStr);
                    break;
                }
            }
        }
    }
    
    
    private static void generate3(char[] charArray) {
        for(int a = 0; a< lengthSourceArray ;a++) {
            charArray[0] = sourceArray[a];
            for (int b = 0; b< lengthSourceArray; b++) {
                charArray[1] = sourceArray[b];
                for (int c= 0; c< lengthSourceArray; c++) {
                    charArray[2] = sourceArray[c];
                    
                    String sStr = new String(charArray);
                    if(EncriptUtil.validate(target, EncriptUtil.sha256Encode(sStr))) {
                        System.out.println(sStr);
                        break;
                    }
                }
            }
        }
    }
    
    private static void generate4(char[] charArray) {
        for(int a = 0; a< lengthSourceArray ;a++) {
            charArray[0] = sourceArray[a];
            for (int b = 0; b< lengthSourceArray; b++) {
                charArray[1] = sourceArray[b];
                for (int c= 0; c< lengthSourceArray; c++) {
                    charArray[2] = sourceArray[c];
                    for (int d=0; d< lengthSourceArray; d++) {
                        charArray[3] = sourceArray[d];
                        String sStr = new String(charArray);
                        System.out.println(sStr);
                        if(EncriptUtil.validate(target, EncriptUtil.sha256Encode(sStr))) return;
                    }
                }
            }
        }
    }
    
    private static void generate5(char[] charArray) {
        for(int a = 0; a< lengthSourceArray ;a++) {
            charArray[0] = sourceArray[a];
            for (int b = 0; b< lengthSourceArray; b++) {
                charArray[1] = sourceArray[b];
                for (int c= 0; c< lengthSourceArray; c++) {
                    charArray[2] = sourceArray[c];
                    for (int d=0; d< lengthSourceArray; d++) {
                        charArray[3] = sourceArray[d];
                        for (int e=0; e< lengthSourceArray; e++) {
                            charArray[4] = sourceArray[e];
                            String sStr = new String(charArray);
                            System.out.println(sStr);
                            if(EncriptUtil.validate(target, EncriptUtil.sha256Encode(sStr))) return;
                        }
                    }
                }
            }
        }
    }
    
    private static void generate6(char[] charArray) {
        for(int a = 0; a< lengthSourceArray ;a++) {
            charArray[0] = sourceArray[a];
            for (int b = 0; b< lengthSourceArray; b++) {
                charArray[1] = sourceArray[b];
                System.out.println(new String(charArray));
                for (int c= 0; c< lengthSourceArray; c++) {
                    charArray[2] = sourceArray[c];
                    for (int d=0; d< lengthSourceArray; d++) {
                        charArray[3] = sourceArray[d];
                        for (int e=0; e< lengthSourceArray; e++) {
                            charArray[4] = sourceArray[e];
                            for (int f=0; f< lengthSourceArray; f++) {
                                charArray[5] = sourceArray[f];
                                String sStr = new String(charArray);
                                if(target.equals(EncriptUtil.sha256Encode(sStr))) {
                                    System.out.println(sStr);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    private static void generate7(char[] charArray) {
        for(int a = 0; a< lengthSourceArray ;a++) {
            charArray[0] = sourceArray[a];
            for (int b = 0; b< lengthSourceArray; b++) {
                charArray[1] = sourceArray[b];
                for (int c= 0; c< lengthSourceArray; c++) {
                    charArray[2] = sourceArray[c];
                    for (int d=0; d< lengthSourceArray; d++) {
                        charArray[3] = sourceArray[d];
                        for (int e=0; e< lengthSourceArray; e++) {
                            charArray[4] = sourceArray[e];
                            for (int f=0; f< lengthSourceArray; f++) {
                                charArray[5] = sourceArray[f];
                                for (int g=0; g< lengthSourceArray; g++) {
                                    charArray[6] = sourceArray[g];
                                    String sStr = new String(charArray);
                                    System.out.println(sStr);
                                    if(EncriptUtil.validate(target, EncriptUtil.sha256Encode(sStr))) return;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    private static void generate8(char[] charArray) {
        for(int a = 0; a< lengthSourceArray ;a++) {
            charArray[0] = sourceArray[a];
            for (int b = 0; b< lengthSourceArray; b++) {
                charArray[1] = sourceArray[b];
                for (int c= 0; c< lengthSourceArray; c++) {
                    charArray[2] = sourceArray[c];
                    for (int d=0; d< lengthSourceArray; d++) {
                        charArray[3] = sourceArray[d];
                        for (int e=0; e< lengthSourceArray; e++) {
                            charArray[4] = sourceArray[e];
                            for (int f=0; f< lengthSourceArray; f++) {
                                charArray[5] = sourceArray[f];
                                for (int g=0; g< lengthSourceArray; g++) {
                                    charArray[6] = sourceArray[g];
                                    for (int h=0; h< lengthSourceArray; h++) {
                                        charArray[7] = sourceArray[h];
                                        String sStr = new String(charArray);
                                        System.out.println(sStr);
                                        if(EncriptUtil.validate(target, EncriptUtil.sha256Encode(sStr))) return;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
}
